// 检查ip地址是否正确
function checkip(ip) {
    var re = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
    return re.test(ip);
}

// 循环form 获取input结果， 并返回字典
function formEachGetDict(attr) {
    var dic = {};
    attr.each(function () {
        dic[$(this).attr('id')] = $(this).val()
    });
    return dic
}

function mapDic() {
    var dic = {};
    var formInput = formEachGetDict($("#mapforms input"));
    var formSelect = formEachGetDict($("#mapforms select"));
    for (k in formInput) {
        dic[k] = formInput[k]
    }
    for (k in formSelect) {
        dic[k] = formSelect[k]
    }
    // var inputdic = JSON.stringify(dic);
    return dic
}

// 每五秒就清空一次error信息
setInterval(function () {
    $(".error-message").html("")
}, 5000);

// 设置名称
function Title(splitNum) {
    var _position = document.location.pathname.split('/')[splitNum];
    if (_position == 1) {
        $("#titleLeg").text("防火墙-北京-内网")
    } else if (_position == 2) {
        $("#titleLeg").text("防火墙-廊坊-机房")
    } else if (_position == 3) {
        $("#titleLeg").text("防火墙-腾讯云")
    } else {
        $("#titleLeg").text("防火墙-未知")

    }
}

function addName(splitNum) {
    var _tablename = document.location.pathname.split('/')[splitNum];
    if (_tablename == 'fw_outmaps') {
        $("#titleLeg").text("外网地址添加")
    } else if (_tablename == 'fw_inmaps') {
        $("#titleLeg").text("内网地址添加")
    } else {
        $("#titleLeg").text("未知-添加")
    }
}



